<%@ include file="/netmarkets/jsp/components/beginWizard.jspf"%>
<%@ taglib prefix="w" uri="http://www.ptc.com/windchill/taglib/wrappers"%>
<%@ taglib prefix="jca" uri="http://www.ptc.com/windchill/taglib/components"%>
<%@taglib uri="http://www.ptc.com/windchill/taglib/fmt" prefix="fmt"%>
<fmt:setBundle basename="ext.generic.wfaugment.processors.processorsResource" />
<fmt:message var="key1"    key="SEARCH_WFAUGMENT" />
<fmt:message var="key2"    key="SEARCH" />
<fmt:message var="key3"    key="CONFIRM" />
<fmt:message var="key4"    key="CANCLE" />
<SCRIPT LANGUAGE="JavaScript">
$(function(){
$("input").keyUp(
function(event){
if(event.keyCode == 13){
return false;
}
}
);
})

function testKey(e){
    var ev=window.event.keyCode||e;
    
    if(ev == 13){
        try {
            var name = document.getElementById('text1').value;
            
            var loader = new ajax.ContentLoader("netmarkets/jsp/ext/generic/part/search.jsp", null, null, 'POST', 'name='+name);

            var resText = null;
            
            if (loader.req.readyState == 4 && loader.req.status == 200) {
                resText = loader.req.responseText;
                
                var names = eval(resText);
                
                var ok=document.getElementsByName("ck");
                var tb=document.getElementById("tb");
		
                for(var k=0;k<ok.length;k++) {
                    tb.deleteRow(k);
                    k=k-1;
		            }
		            
                for(var i=0;i<names.length;i++) {
                    var name = names[i]["name"];
                    var val = names[i]["val"];
                    add(tb,name,i,val);
                }
            }
		    } catch (e) {

        }
   }
}

function clickCompleteButton() {
    var name = document.getElementById('text1').value;
	 
    try {
        var loader = new ajax.ContentLoader("netmarkets/jsp/ext/generic/part/search.jsp", null, null, 'POST', 'name='+name);

        var resText = null;
        
        if (loader.req.readyState == 4 && loader.req.status == 200) {
            resText = loader.req.responseText;
            
            var names = eval(resText);
            var ok=document.getElementsByName("ck");
            var tb=document.getElementById("tb");
            
            for(var k=0;k<ok.length;k++){
                tb.deleteRow(k);
                k=k-1;
            }
		
            for(var i=0;i<names.length;i++){
                var name = names[i]["name"];
                var val = names[i]["val"];
                add(tb,name,i,val);
            }
        }
		} catch (e) {
			
		}
}

 function add(tb,name,i,val)  
 {
   var mytr=tb.insertRow();
   mytr.setAttribute("id","r"+i);  
   var mytd_1=mytr.insertCell();  
   var mytd_2=mytr.insertCell();  
   mytd_1.innerHTML="<input type='checkbox' name='ck' value='"+name+"' />";  
   
   //mytd_2.innerText=name;
   if(navigator.appName.indexOf("Explorer") > -1){
        mytd_2.innerText=name;  
   } else{
        mytd_2.textContent=name;  
   }
   
   mytd_2.innerText=name;
 }
 
 function bcancel()
{
	window.close();
}

<%
    String sOid= request.getParameter("type");
	/** searchType，默认值为Reset，传递值为：
		add: 表示在原来的数据中追加
		Reset：表示替换运来的值
	*/
	String searchType = request.getParameter("searchType");
    request.setAttribute("sOid",""+sOid);
    request.setAttribute("searchType",""+searchType);
%>
function bconfirm() {
	 var names = document.getElementsByName("ck");
	 
	 var cid = "${sOid}";
	 var searchType = "${searchType}";
	 var showObject = window.opener.document.getElementById(cid);
	 
	 var message = "";
	 var splitValue = "&";
	 for(var i=0;i<names.length;i++) {
		if(names[i].checked == true) {
			if("add" == searchType) {//追加时，过滤重复的
				if(showObject.value.indexOf(names[i].value) < 0) {
					message += names[i].value + splitValue;
				}
			} else {
				message += names[i].value + splitValue;
			}
		}
	 }
	 
	 var selectLastValue = message.substring(0, message.lastIndexOf(splitValue));//最终选择的所有值中需要加入到组件的值
	 if("" != selectLastValue) {
		 if("add" == searchType) {//追加
			 if(showObject.value == "") {
				 showObject.value = selectLastValue;
			 } else {
				 showObject.value = showObject.value + "&" + selectLastValue ;
			 }
		 } else {//替换
			 showObject.value = selectLastValue;
		 }
	 }
	 self.close();
	 return;
 }
</SCRIPT>
<center>
<table>
	<tr>
		<td>
			<w:label value="${key1}:"></w:label>
		<!--	<w:textBox name="text" id="text1" value="" maxlength="15" onkeyup="testKey(event);"></w:textBox>-->
		<!--<input type="text" id="text1" name="text1" onkeypress="testKey(event);"> -->
		
		<input type="text" id="text1" name="text1" onkeypress="testKey();">
			<w:button name="submit" id="submit" value="${key2}" onclick="javascript:clickCompleteButton()"    onkeypress="javascript:testKey()"></w:button>
			
		<span id="test1" style="display:none">
		<input type="text" id="c" name="c" borderStyle="0" >
			
		</td>
	</tr>
</table>

<table id="tb">
</table>
	<w:button name="confirm" value="${key3}" onclick="bconfirm()"></w:button>
	<w:button name="cancel" value="${key4}" onclick="bcancel()"></w:button>
</center>  	
<%@ include file="/netmarkets/jsp/util/end.jspf"%>